#include"Sort.h"

void Swap(int* x, int* y)
{
	int temp = *x;
	*x = *y;
	*y = temp;
}

void InsertSort(int* a, int n)
{
	for (int i = 0; i < n-1; i++)
	{
		int end = i;
		int temp = a[end + 1];
		while (end >= 0)
		{
			if (a[end] > temp)
			{
				Swap(&a[end], &a[end+1]);
				end--;
			}
			else
			{
				break;
			}
		}
		Swap(&a[end + 1], &temp);
	}
}

void ShellSort(int* a, int n)
{
	int gap = n;
	while (gap>1)
	{
		gap /= 2;
		for (int i = 0; i < n - gap; i++)
		{
			int end = i;
			int temp = a[end + gap];
			while (end >=0 )
			{
				if (a[end] > temp)
				{
					Swap(&a[end], &a[end + gap]);
					end = end - gap;
				}
				else
				{
					break;
				}
			}
			Swap(&a[end + gap], &temp);
		}
	}
}